package com.darkplanet.management.controller;

import com.darkplanet.management.service.RequirementService;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/ProjectneedDeleteServlet")
public class ProjectneedDeleteServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ObjectMapper objectMapper = new ObjectMapper();
        String requirement_id = request.getParameter("json");
        String[] arr1=objectMapper.readValue(requirement_id,String[].class);
        RequirementService requirementService = new RequirementService();
        for (int i = 0; i <arr1.length ; i++) {
            int j = Integer.parseInt(arr1[i]);
            requirementService.delete(j);
//            System.out.println(arr1[i]);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
